package com.songlanyun.modules.servicegoods.entity;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.songlanyun.common.drive.RootEntity;
import com.songlanyun.common.utils.SpringContextUtils;
import com.songlanyun.modules.group.entity.ProductGoodsGroupEntity;
import com.songlanyun.modules.group.service.ProductGoodsGroupService;
import com.songlanyun.modules.servicegoods.service.ServiceGoodsGroupService;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.Range;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

/**
 * 商家的服务分组，只用来在商家店铺内展示
 *
 * @author wuchao
 * @email sunlightcs@gmail.com
 * @date 2020-12-15 11:51:34
 */
@Data
@TableName("yxt_service_goods_group")
public class ServiceGoodsGroup extends RootEntity<Long, ServiceGoodsGroup> implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     *
     */
    @TableId
    private Long id;
    /**
     * 店铺id
     */
    @NotNull(message = "店铺id不能为空")
    private Long shopId;
    /**
     * 上级分组
     */
    @NotNull(message = "上级分组不能为空")
    private Long parentId;
    /**
     * 服务分组名称
     */
    @NotBlank(message = "服务分组名称不能为空")
    @Length(min = 1, max = 50, message = "服务分组名称长度在1-50个字")
    private String name;
    /**
     * 分组图标
     */
    private String coverImage;
    /**
     * 介绍
     */
    @Length(min = 0, max = 500, message = "介绍长度在1-500个字")
    private String introduction;
    /**
     * 顺序
     */
    @Range(min = 0,max = 999999,message = "顺序值介于0到999999之间")
    private Integer orderIndex;
    /**
     *
     */
    @TableField(fill = FieldFill.INSERT)
    private Date createTime;
    /**
     *
     */
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private Date updateTime;

    @Override
    public Long getIdentity() {
        return id;
    }

    /**
     * 获得所有子分组
     * @return
     */
    @JsonIgnore
    public List<ServiceGoodsGroup> loadChildren()
    {
        return ((ServiceGoodsGroupService) SpringContextUtils.getBean("serviceGoodsGroupService")).getChildren(this.getId());
    }
}
